home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / printing / std file saver / source / mypdef_7_prgeneral.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  3.8 KB  |  149 lines

  1. /*
  2. ** Copyright 1991-1996 Apple Computer. All rights reserved.
  3. **
  4. **    You may incorporate this sample code into your applications without
  5. **    restriction, though the sample code has been provided "AS IS" and the
  6. **    responsibility for its operation is 100% yours.  However, what you are
  7. **    not permitted to do is to redistribute the source as "DSC Sample Code"
  8. **    after having made changes. If you're going to re-distribute the source,
  9. **    we require that you make it clear in the source that the code was
  10. **    descended from Apple Sample Code, but that you've made changes.
  11. */
  12.  
  13. #include <Printing.h>
  14. #include <Files.h>
  15.  
  16. #include "driverTypes.h"
  17.  
  18. enum {    // PrGeneral result codes as defined in IM:Imaging, 9-74
  19.     prGeneralNoErr = 0,
  20.     noSuchResolution,
  21.     opcodeNotSupported
  22. };
  23.  
  24. pascal void FilePrGeneral(Ptr pData);
  25.  
  26. #if defined(__MWERKS__)
  27. asm void __Startup__ (void);
  28. asm void __Startup__ (void)
  29. {
  30.     JMP    FilePrGeneral
  31. }
  32. #endif
  33.  
  34. static void GetResolution(TGetRslBlk *data)
  35. {
  36. #ifdef VAR_RESOLUTION
  37.     SysEnvRec theWorld;
  38.     SysEnvirons(1, &theWorld);
  39.  
  40.     if (!theWorld.hasColorQD) {
  41.         // if we don't have color QD, we can't have var-res
  42.         setPrintErr(noErr);
  43.         data->iRgType = VER_SHORT;
  44.         data->iError = noErr;
  45.         data->xRslRg.iMin = 0;
  46.         data->xRslRg.iMax = 0;
  47.         data->yRslRg.iMin = 0;
  48.         data->yRslRg.iMax = 0;
  49.         data->iRslRecCnt = 1;
  50.         data->rgRslRec[0].iXRsl = 72;
  51.         data->rgRslRec[0].iYRsl = 72;
  52.     } else {
  53.         // variable resolution. Wee-haw.
  54.     }
  55. #else
  56.     setPrintErr(noErr);
  57.     data->iError = noErr;
  58.     data->iRgType = VER_SHORT;
  59.     data->xRslRg.iMin = 0;
  60.     data->xRslRg.iMax = 0;
  61.     data->yRslRg.iMin = 0;
  62.     data->yRslRg.iMax = 0;
  63.     data->iRslRecCnt = 1;
  64.     data->rgRslRec[0].iXRsl = 72;
  65.     data->rgRslRec[0].iYRsl = 72;
  66. #endif
  67. }
  68.  
  69. static void SetResolution(TSetRslBlk *data)
  70. {
  71. #ifdef VAR_RESOLUTION
  72.     SysEnvRec theWorld;
  73.     SysEnvirons(1, &theWorld);
  74.  
  75.     if (!theWorld.hasColorQD) {
  76.         // we can't support setting the resolution if we only said we
  77.         // had one choice and no range. Error.
  78.         setPrintErr(opcodeNotSupported);
  79.         data->iError = opcodeNotSupported;
  80.     } else {
  81.         setPrintErr(noErr);
  82.         data->iError = noErr;
  83.         // Change the resolution to what they asked for
  84.     }
  85. #else
  86.     setPrintErr(opcodeNotSupported);
  87.     data->iError = opcodeNotSupported;
  88. #endif
  89. }
  90.  
  91. static void DraftBits(TDftBitsBlk *data)
  92. {
  93. #ifdef DEBUG
  94.     DebugStr("\pprGeneral DraftBits called, and I haven't written it yet!");
  95. #endif
  96.     setPrintErr(noErr);
  97.     data->iError = opcodeNotSupported;
  98. }
  99.  
  100. static void GetRotation(TGetRotnBlk *data)
  101. {
  102.     THPrint    printHandle = data->hPrint;
  103.     Rect    pageRect = (**printHandle).prInfo.rPage;
  104.     short    width = pageRect.right - pageRect.left;
  105.     short    height = pageRect.bottom - pageRect.top;
  106.  
  107.     // the following logic is overly simplistic and won't deal with
  108.     // pages that are designed to be landscape (i.e. ledger instead
  109.     // of tabloid), but it works for the sizes I've defined. Note
  110.     // that there just isn't a good way to deal with LEF pages in
  111.     // the old printing architecture. GX has a way of dealing with
  112.     // them, but if you were interested in GX, you wouldn't be
  113.     // looking at this sample, now would you? -DaveP
  114.  
  115.     data->fLandscape = (width > height);
  116.     data->iError = noErr;
  117.     setPrintErr(noErr);
  118. }
  119.  
  120. // refer to Inside Macintosh vol. V and the relevant Technical Notes for details 
  121. pascal void FilePrGeneral(Ptr pData)
  122. {
  123.     TGnlData *localData = (TGnlData *)pData;
  124.     setPrintErr(prGeneralNoErr);
  125.     switch (localData->iOpCode) { 
  126.         case getRslDataOp:
  127.             GetResolution((TGetRslBlk *)pData);
  128.             break;
  129.         case setRslOp:
  130.             SetResolution((TSetRslBlk *)pData);
  131.             break;
  132.         case draftBitsOp:
  133.         case noDraftBitsOp:
  134.             DraftBits((TDftBitsBlk *)pData);
  135.             break;
  136.         case getRotnOp:
  137.             GetRotation((TGetRotnBlk *)pData);
  138.             break;
  139.         default:
  140. #ifdef DEBUG
  141.             DebugStr("\pprGeneral called with a selctor I don't understand.");
  142. #endif
  143.             setPrintErr(opcodeNotSupported);
  144.             localData->iError = opcodeNotSupported;
  145.             break;
  146.     }
  147. }
  148.  
  149.